#
# "@(#) $Id: StatusWidget.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from qt import *
from PixmapPushButton import *
from StatusLogoProgressView import *
from StatusPlayerProgressView import *
from StatusRipperProgressView import *
from StatusEncoderProgressView import *
from StatusImporterProgressView import *
from StatusBurnerProgressView import *
from StatusImporterProgressView import *
from StatusCDMounterProgressView import *

#from StatusDellMounterProgressView import *
#from StatusDellImporterProgressView import *
#from StatusDellExporterProgressView import *
#from StatusDellSyncerProgressView  import *


## Ipod Support
#rom StatusPodExporterProgressView import *
#rom StatusPodImporterProgressView import *
#rom StatusPodUpdaterProgressView import *

from StatusDownloadProgressView import *
from StatusBrowserProgressView import *
from StatusUploaderProgressView import *
from StatusSyncerProgressView import *
from Utils.Paths import *

class StatusWidget(QWidget):
	def __init__(self,container):
		QWidget.__init__(self,container)
		self.setFixedHeight(45)
		self.setMinimumWidth(160)
		#self.left = QPixmap(art("backgroundstatusleft.png"))
		#self.right = QPixmap(art("backgroundstatusright.png"))
		#self.middle = QBrush()
		#self.middle.setPixmap(QPixmap(art("backgroundstatusmiddle.png")))
		backColor=QColor(Settings.settings().get('ColorR'),Settings.settings().get('ColorG'),Settings.settings().get('ColorB'))
		self.setPaletteBackgroundColor(backColor)
		vlayout = QVBoxLayout(self)
		vlayout.setMargin(0)
		hlayout = QHBoxLayout(self)
		vlayout.addLayout(hlayout)
		#hlayout.addItem(QSpacerItem(10,1,QSizePolicy.Fixed,QSizePolicy.Fixed))
		arrow = QIconSet(QPixmap(art("buttonstatusarrow.png")))
		self.advanceButton = SmallPixmapPushButton(arrow,"",self)
		QToolTip.add(self.advanceButton,i18n("Switch between status views"))
		QObject.connect(self.advanceButton,SIGNAL("clicked()"),self.nextStatus)
		hlayout.addWidget(self.advanceButton)
		self.advanceButton.hide()
		#hlayout.addItem(QSpacerItem(4,1,QSizePolicy.Fixed,QSizePolicy.Fixed))
		self.stack = QWidgetStack(self)
		self.stack.setFrameStyle(QFrame.Box)
		self.stack.setLineWidth(2)
		self.stack.setMargin(0)
		hlayout.addWidget(self.stack)
		self.addLogoProgressView(self.stack)
		self.addPlayerProgressView(self.stack)
		self.addRipperProgressView(self.stack)
		self.addEncoderProgressView(self.stack)
		self.addBurnerProgressView(self.stack)
		self.addImporterProgressView(self.stack)
		self.addCDMounterProgressView(self.stack)
		'''		
		self.addPodExporterProgressView(self.stack)
		self.addPodImporterProgressView(self.stack)
		self.addPodUpdaterProgressView(self.stack)
		'''		
		self.addDownloadProgressView(self.stack)
		self.addBrowserProgressView(self.stack)
		self.addUploaderProgressView(self.stack)
		self.addSyncerProgressView(self.stack)
		self.views = []
		#hlayout.addItem(QSpacerItem(25,1,QSizePolicy.Fixed,QSizePolicy.Fixed))
		self.stack.setFixedHeight(45)

	def addLogoProgressView(self,container):
		self.logoProgressView = StatusLogoProgressView(container)

	def addPlayerProgressView(self,container):
		self.playerProgressView = StatusPlayerProgressView(container,self)

	def addRipperProgressView(self,container):
		self.ripperProgressView = StatusRipperProgressView(container,self)

	def addEncoderProgressView(self,container):
		self.encoderProgressView = StatusEncoderProgressView(container,self)

	def addBurnerProgressView(self,container):
		self.burnerProgressView = StatusBurnerProgressView(container,self)

	def addImporterProgressView(self,container):
		self.importerProgressView = StatusImporterProgressView(container,self)
	
	def addCDMounterProgressView(self,container):
		self.cdMounterProgressView = StatusCDMounterProgressView(container,self)
	'''
		
	def addPodImporterProgressView(self,container):
		self.podImporterProgressView = StatusPodImporterProgressView(container,self)

	def addPodExporterProgressView(self,container):
		self.podExporterProgressView = StatusPodExporterProgressView(container,self)

	def addPodUpdaterProgressView(self,container):
		self.podUpdaterProgressView = StatusPodUpdaterProgressView(container,self)
	'''
	def addDownloadProgressView(self,container):
		self.downloadProgressView = StatusDownloadProgressView(container,self)

	def addBrowserProgressView(self,container):
		self.browserProgressView = StatusBrowserProgressView(container,self)

	def addUploaderProgressView(self,container):
		self.uploaderProgressView = StatusUploaderProgressView(container,self)

	def addSyncerProgressView(self,container):
		self.syncerProgressView = StatusSyncerProgressView(container,self)
	'''
	def paintEvent(self,ev):
		global _left,_middle,_right,_logo
		r = self.rect()
		p = QPainter()
		p.begin(self)
		p.setPen(Qt.NoPen)
		p.drawPixmap(QPoint(0,0),self.left)
		p.drawPixmap(QPoint(r.width()-self.right.width(),0),self.right)
		p.setBrush(self.middle)
		fill = QRect(self.left.width(),0,r.width()-self.left.width()-self.right.width(),self.left.height())
		p.drawRect(fill)
		p.end()
	'''
	def showStatus(self,view):
		#print "attempting to show",view
		try: index = self.views.index(view)
		except:
			self.views.append(view)
			self.stack.raiseWidget(view)
			if len(self.views)>1:
				self.advanceButton.show()
	
	def hideStatus(self,view):
		#print "attempting to hide",view
		try:
			index = self.views.index(view)
			self.views.remove(view)
			if len(self.views)==0:
				self.stack.raiseWidget(self.logoProgressView)
			elif index>=len(self.views):
				self.stack.raiseWidget(self.views[0])
			else:
				self.stack.raiseWidget(self.views[index])
			if len(self.views)<=1:
				self.advanceButton.hide()
		except: pass
	
	def nextStatus(self):
		if len(self.views)>0:
			index = self.views.index(self.stack.visibleWidget())+1
			if index>=len(self.views):
				index = 0
			self.stack.raiseWidget(self.views[index])
